<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('标准主列表')"/>
    <th:block th:include="include :: layout-latest-css"/>

</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <input name="standardType" th:value="${standardType}" type="hidden"/>
                        </li>

                        <li>
                            标准名称：<input name="standardName" type="text"/>
                        </li>

                        <li>
                            作物名称：<input name="cropNameCn" type="text"/>
                        </li>
                        <li>
                            作物品种：<input name="cropVarietiesCn" type="text"/>
                        </li>
                        <li class="select-time">
                            <label>标准： </label>
                            <input class="time-input" id="beginTime" name="params[beginTime]" placeholder="开始时间"
                                   th:value="${beginTime}" type="text"/>
                            <span>-</span>
                            <input class="time-input" id="endTime" name="params[endTime]" placeholder="结束时间"
                                   th:value="${endTime}" type="text"/>
                        </li>
                        <li>
                            适宜季节：<select name="season" th:with="type=${@dict.getType('nc_season')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncStandard:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncStandard:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncStandard:remove">
                <i class="fa fa-remove"></i> 删除
            </a>-->
            <a class="btn btn-info" onclick="$.table.importExcel()">
                <i class="fa fa-upload"></i> 导入
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:ncStandard:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table data-mobile-responsive="true" id="bootstrap-table"></table>
        </div>

    </div>
    <div class="bottom-btns"></div>
</div>

<div th:include="include :: footer"></div>
<th:block th:include="include :: layout-latest-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncStandard:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncStandard:remove')}]];
    var datas = [[${@dict.getType('nc_season')}]];
    var prefix = ctx + "system/ncStandard";

    var standardType = [[${standardType}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add?standardType=" + standardType,
            updateUrl: prefix + "/edit/{id}",
            configStandardUrl: prefix + "/config/{id}",
            removeUrl: prefix + "/remove",
            importUrl: prefix + "/importData/" + standardType,
            importTemplateUrl: prefix + "/importTemplate",
            exportUrl: prefix + "/export",
            modalName: "育苗标准",
            sortName:'createTime',
            sortOrder:'desc',
            showExport: true,
            columns: [{checkbox:true}, {
                title: '序号',
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
                {
                    field: 'standardId',
                    title: '标准id',
                    visible: false
                },
                {
                    field: 'standardName',
                    title: '标准名称',
                },
                {
                    field: 'pic',
                    title: '图片',
                    sortable: false,
                    formatter: function (value, item, index) {
                        return $.table.showPic(item.pic);
                    }
                },
                {
                    field: 'cropTypeCn',
                    title: '作物类别',
                    sortable: true
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: true
                },
                {
                    field: 'cropVarietiesCn',
                    title: '作物品种',
                    sortable: true
                },
                {
                    field: 'season',
                    title: '适宜季节',
                    sortable: true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(datas, item.season);
                    }
                },
                {
                    field: 'totalCycle',
                    title: '总周期(天)',
                    sortable: true
                }, {
                    field: 'createBy',
                    title: '制作人',
                    sortable: true
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '启用',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },{
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.standardId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editStandardConfig(\'' + row.standardId + '\')"><i class="fa fa-edit"></i>配置周期</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.standardId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        var btns = [{
            name: '工作记录',
            url: ctx + 'system/ncNormalWorks?workType=1',
            id: 'normal-work'
        }];
        addBtns(btns);

    });

    /* 状态显示 */
    function statusTools(row) {
        if (row.status == 1) {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.standardId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.standardId + '\')"></i> ';
        }
    }

    /* -停用 */
    function disable(stId) {
        $.modal.confirm("确认要停用吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "standardId": stId, "status": 2 });
        })
    }

    /* 启用 */
    function enable(stId) {
        $.modal.confirm("确认要启用吗？", function() {
            $.operate.post(prefix + "/changeStatus", { "standardId": stId, "status": 1 });
        })
    }

    if([[${standardType}]] == 1){
        setTitle("育苗标准",false)
    }else {
        setTitle("生产标准",false)
    }


</script>

<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <!--                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据-->
                <!--                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>-->
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</body>
</html>